package com.dyna.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dyna.core.LambdaQueryWrapperX;
import com.dyna.domain.resp.PageResult;
import com.dyna.foundation.domain.entity.SysDictData;
import com.dyna.foundation.domain.entity.SysDictType;
import com.dyna.foundation.domain.req.SysDictDataReq;
import com.dyna.foundation.domain.req.SysDictTypePageReq;
import com.dyna.foundation.domain.req.SysDictTypeReq;
import com.dyna.foundation.domain.resp.SysDictTypeResp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
* @author zhoucaiwang
*/

@Mapper
public interface SysDictTypeMapper extends BaseMapperX<SysDictType> {

    /**
     * 字典类型分页查询
     * @return List<SysDictTypeResp>
     */
    List<SysDictTypeResp> querySysDictTypePage(@Param("req") SysDictTypeReq req);

    /**
     * 根据字典类型和value获取详细信息
     * @param dictType 字典类型
     * @return 字典数据
     */
    default List<SysDictType> selectByDictType(String dictType) {
        return selectList(new LambdaQueryWrapper<SysDictType>()
                .eq(SysDictType::getDictType, dictType));
    }

    /**
     * 根据类型查询
     * @param dictType 字典类型
     * @return List<SysDict>
     */
    default List<SysDictType> queryByType(String dictType) {
        return selectList(
                new LambdaQueryWrapper<SysDictType>()
                .eq(SysDictType::getDictType,dictType)
        );
    }

    Boolean delSysDictType(@Param("dictId") Integer dictId);

    /**
     * 修改字典类型状态
     * @param dictId 字典类型id
     * @param status 状态
     * @return Boolean
     */
    Boolean changeSysDictTypeStatus(@Param("dictId") Integer dictId, @Param("status") Integer status);

    /**
     * 根据查询指定类型字典数据
     * @param req 查询条件
     * @return 字典数据
     */
    List<SysDictData> querySysDictDataPage(@Param("req") SysDictDataReq req);

    /**
     * 新增字典数据
     * @param sysDictData data
     * @return Boolean
     */
    Boolean insertSysDictData(SysDictData sysDictData);

    /**
     * 编辑字典数据
     * @param sysDictData data
     * @return Boolean
     */
    Boolean updateSysDictData(SysDictData sysDictData);

    /**
     * 删除字典数据
     * @param dictId 字典数据id
     * @return Boolean
     */
    Boolean delSysDictData(@Param("dictId") Integer dictId);

    /**
     * 修改字典数据状态
     * @param dictId dictId
     * @param status status
     * @return Boolean
     */
    Boolean changeSysDictDataStatus(@Param("dictId") Integer dictId, @Param("status") Integer status);

    /**
     * 批量查询字典数据
     * @param dictTypeList 字典类型
     * @return List<SysDictData>
     */
    List<SysDictData> queryBatchSysDictList(@Param("dictTypeList") List<String> dictTypeList);

    /**
     * 根据字典类型查询字典数据
     * @param dictType 字典类型
     * @return List<SysDictData>
     */
    List<SysDictData> querySysDictDataByType(@Param("dictType") String dictType);

    default SysDictType selectByName(String name) {
        return selectOne(SysDictType::getDictName, name);
    }

    default SysDictType selectByType(String type) {
        return selectOne(SysDictType::getDictType, type);
    }

    default PageResult<SysDictType> selectPage(SysDictTypePageReq reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SysDictType>()
                .likeIfPresent(SysDictType::getDictName, reqVO.getName())
                .likeIfPresent(SysDictType::getDictType, reqVO.getType())
                .eqIfPresent(SysDictType::getStatus, reqVO.getStatus())
                .betweenIfPresent(SysDictType::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SysDictType::getDictId));
    }

}




